package com.sti.framework.models.System.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sti.framework.core.controller.BaseController;
import com.sti.framework.core.web.ResponseBodyEntity;
import com.sti.framework.models.System.data.BasicsAppArgument;
import com.sti.framework.models.System.data.MenuManage;
import com.sti.framework.models.System.data.MenuManageSearchWhere;
import com.sti.framework.models.System.mapper.MenuManageMapper;
import com.sti.framework.models.System.service.BasicsAppArgumentService;
import com.sti.framework.models.System.service.MenuManageService;
import io.swagger.annotations.Api;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 模块： 系统设置 System
 * 表格： 菜单管理 MenuManage
 *
 * @author AutoApi
 */
@RestController
@RequestMapping("/Api/MenuManage")
@Api(tags = "菜单管理", value = "系统设置")
public class MenuManageController extends BaseController<MenuManageMapper, MenuManage, MenuManageSearchWhere> {

    @Inject
    private MenuManageService menumanageService;
    @Inject
    private BasicsAppArgumentService basicsAppArgumentService;

    /**
     * 列表
     * @param Page  分页内容
     * @param searchWhere   搜索内容
     * @return
     *
     *
     @ApiOperation(value = "列表", notes = "列表")
     @ApiImplicitParam(name = "token", value = "登陆后获取的签名", paramType = "header", dataTypeClass = String.class, required = true)
     @Authorizations({
         @Authorization(tag = "/List", describes = "列表"),
     })
     @GetMapping("/List")
     public ResponseBodyEntity<SimplePage<MenuManage>> List(Page page, MenuManageSearchWhere searchWhere) {
     return ResponseBodyEntity.success(menumanageService.getListPage(page, searchWhere));
     };
     */

    @GetMapping("/ListData")
    public ResponseBodyEntity ListData() {
        LambdaQueryWrapper<MenuManage> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.isNull(MenuManage::getParentId);
        List<MenuManage> list = menumanageService.getList(lambdaQueryWrapper);
        if(!CollectionUtils.isEmpty(list)){
            //获取子数据
            for (MenuManage menuManage : list) {
                lambdaQueryWrapper.clear();
                lambdaQueryWrapper.eq(MenuManage::getParentId,menuManage.getId());
                menuManage.setChildren(menumanageService.getList(lambdaQueryWrapper));
            }
        }
        return ResponseBodyEntity.success(list);
    }

    @GetMapping("/appArgument")
    public BasicsAppArgument ListDaappArgumentta() {
        BasicsAppArgument one = basicsAppArgumentService.getOne(new LambdaQueryWrapper<>());
        one.setCode("0");
        one.setMsg("");
        return one;
    }
}